package _interview75;

import java.util.Arrays;
import java.util.HashMap;

/**
 * 2352. 相等行列对
 */
public class No2352 {
    public int equalPairs(int[][] grid) {
        int n = grid.length;
        HashMap<String, Integer> map = new HashMap<>();
        for (int[] ints : grid) {
            map.put(Arrays.toString(ints), map.getOrDefault(Arrays.toString(ints), 0) + 1);
        }

        int answer = 0;
        int[][] copyGrid = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                copyGrid[i][j] = grid[j][i];
            }
            String key = Arrays.toString(copyGrid[i]);
            if (map.containsKey(key)) {
                answer += map.get(key);
            }
        }
        return answer;
    }
}
